import { NextRequest, NextResponse } from 'next/server';
import { CategoryService } from '@/app/lib/DataBase/database';

// 根据ID获取视频
export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params;
  console.log('⏰ ~ GET ~ id:', id)
  try {
    const data = await CategoryService.getCategoryById(id);
    
    if (!data || data.length === 0) {
      return NextResponse.json({ 
        success: false, 
        message: '分类不存在' 
      }, { status: 404 });
    }
    
    return NextResponse.json({ 
      success: true, 
      data: data[0] 
    });
  } catch (error) {
    console.error('获取视频失败:', error);
    return NextResponse.json({ 
      success: false, 
      message: '获取视频失败',
      error: error instanceof Error ? error.message : '未知错误'
    }, { status: 500 });
  }
}